<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:c="http://java.sun.com/jstl/core"
      xmlns:j="http://metalframework.org">
      
	<body>
		<ui:composition template="/WEB-INF/templates/template.xhtml">
			<ui:define name="content">
				<j:keep id="ownerId" value="#{param.id}" />

				<c:choose>
					<c:when test="#{empty ownerId}">
						<j:keep id="currentOwner" value="#{owner}" dependsOn="ownerId" />
					</c:when>
					<c:otherwise>
						<j:keep id="currentOwner" value="#{clinic.getOwnerById(ownerId)}" dependsOn="ownerId" />
					</c:otherwise>
				</c:choose>
				
				<h2>
					<c:if test="#{empty ownerId}">
						<h:outputText value="New " />
					</c:if>
					Owner:
				</h2>

				<h:form>
					<h:panelGrid columns="1" styleClass="form">
						<h:column>
							<h:outputLabel value="First Name:" for="firstName" />
							<h:message for="firstName" styleClass="errors" />
							<br />
							<h:inputText value="#{currentOwner.firstName}" id="firstName" size="30" maxlength="80" />
						</h:column>
						<h:column>
							<h:outputLabel value="Last Name:" for="lastName" />
							<h:message for="lastName" styleClass="errors" />
							<br />
							<h:inputText value="#{currentOwner.lastName}" id="lastName" size="30" maxlength="80" />
						</h:column>
						<h:column>
							<h:outputLabel value="Address:" for="address" />
							<h:message for="address" styleClass="errors" />
							<br />
							<h:inputText value="#{currentOwner.address}" id="address" size="30" maxlength="80" />
						</h:column>
						<h:column>
							<h:outputLabel value="City:" for="city" />
							<h:message for="city" styleClass="errors" />
							<br />
							<h:inputText value="#{currentOwner.city}" id="city" size="30" maxlength="80" />
						</h:column>
						<h:column>
							<h:outputLabel value="Telephone:" for="telephone" />
							<h:message for="telephone" styleClass="errors" />
							<br />
							<h:inputText value="#{currentOwner.telephone}" id="telephone" size="20" maxlength="20" />
						</h:column>
						<h:column>
							<span class="submit">
								<c:choose>
									<c:when test="#{empty ownerId}">
										<h:commandButton action="#{clinic.addOwner(currentOwner)}"
														 value="Add Owner" />
									</c:when>
									<c:otherwise>
										<h:commandButton action="#{clinic.updateOwner(ownerId, currentOwner)}"
														 value="Update Owner" />
									</c:otherwise>
								</c:choose>
							</span>
						</h:column>
					</h:panelGrid>
				</h:form>
			</ui:define>
		</ui:composition>
	</body>
</html>
